using System;
using Bugzproxy;

class ListBugClass {
  static public int Main( string[] args ) {
    ////////////////////////////////////////////////////////////
    // Use common class to get all arguments
    SimpleAppArgs argParser 
      = new SimpleAppArgs( "ListBug.exe", 
                           "Program to list the server information about bug 1" );
    // If parsing fails, bail out
    if ( ! argParser.Parse( args ) ) { 
      return 1; 
    }
    Console.WriteLine( "Using server {0}:{1}/{2}", argParser.Host, argParser.Port, argParser.Path );
    Console.WriteLine( "Using username {0} and password {1}", argParser.User, argParser.Password );
    // Construct server, based on arguments, setup tracer if user set option
    Server server 
      = new Server( argParser.Host, argParser.Port, argParser.Path );
    if ( argParser.Trace ) { 
      server.TraceWriter = System.Console.Out; 
    }
	server.Login(argParser.User, argParser.Password, true);
    ////////////////////////////////////////////////////////////
    // Real program starts here
    Console.WriteLine( "Id\tAlias\tSummary\tCreated\tChanged" );
    // We may need a login to access this bug, but we try without
    Bug b;
    try {
      b = server.GetBug( 1 );
    }
    catch (Exception e) {
      Console.WriteLine( "An exception occured. Try running with --trace? Exception follows");
      Console.WriteLine( e );
      return 1;
    }
    Console.WriteLine( b.Id + "\t" + b.Alias + "\t" + b.Summary
           + "\t" + b.Created + "\t" + b.Changed );
    return 0;
  }
}
